<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="../static/jquery-1.7.2.js"></script>
    <link rel="stylesheet" type="text/css" href="../static/bootstrap.min.css">
    <style>
        .item {
            width: 100px;
            height: 50px;
            border: solid 1px rgb(42, 156, 156);
            float: left;
            margin-right: 10px;
        }
    </style>
</head>
<body>
<div class="container">
    <h2 class="page-header">点击切换颜色</h2>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
</div>
</body>
<script type="text/javascript">
    /*$(".item").click(function () {
        $(this).css('background', 'pink');
        return false;
    });*/
    let items = document.getElementsByClassName('item');
    for (let i = 0; i < items.length; i++) { // var 定义的 i = 3，会报错。let就不会
        items[i].onclick = function () {
            // this.style.background = 'pink';
            items[i].style.background = 'pink';
        };
    }
</script>
</html>